import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ZhuCe extends JFrame  implements ActionListener {
    JTextField name = new JTextField(10);
    JTextField age = new JTextField(10);
    JRadioButton male = new JRadioButton("男",true);
    JRadioButton female = new JRadioButton("女");
    JCheckBox hobby1 = new JCheckBox("java");
    JCheckBox hobby2 = new JCheckBox("VC");
    JTextArea intro = new JTextArea(4,5);
    JButton ok = new JButton("ok");
    JButton reset = new JButton("reset");


    public ZhuCe() {
        this.setTitle("注册");
        this.setSize(180,450);

        Container c = this.getContentPane();
        c.add(new JLabel(new ImageIcon("img//www.jpg")), BorderLayout.NORTH);

        JPanel jp = new JPanel();
        jp.setLayout(new FlowLayout(FlowLayout.LEFT,20,2));

        jp.add(new JLabel("姓名"));
        jp.add(name);
        jp.add(new JLabel("年龄"));
        jp.add(age);
        jp.add(new JLabel("性别"));
        jp.add(male);
        jp.add(female);
        //实现按钮互斥
        ButtonGroup bt = new ButtonGroup();
        bt.add(female);
        bt.add(male);

        jp.add(new JLabel("擅长"));
        jp.add(hobby1);
        jp.add(hobby2);


        jp.add(new JLabel("自我介绍"));
        jp.add(intro);

        jp.add(ok);
        jp.add(reset);

       ok.addActionListener(this);
       reset.addActionListener(this);
        c.add(jp);

        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
//    JTextField no1 = new JTextField(7);
//    JTextField no2 = new JTextField(7);
//    JTextField no3 = new JTextField(7);

    public static void main(String[] args) {
        new ZhuCe();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==ok) {
            String mes ="姓名:"+name.getText()+"年龄："+age.getText();

            if(male.isSelected())
                mes+="性别："+male.getText();
            else mes+="性别"+female.getText();

            if(hobby1.isSelected())
                mes+="擅长："+hobby1.getText();
            if(hobby2.isSelected())
                mes+="擅长："+hobby2.getText();
            mes+="自我介绍"+intro.getText();

            JOptionPane.showMessageDialog(getParent(),mes);
        }
        if(e.getSource()==reset) {
            name.setText("");
            age.setText("");
            male.setSelected(true);//按钮
            hobby1.setSelected(false);
            hobby2.setSelected(false);
            intro.setText("");
        }
    }
}
